//
//  UFNetWorkAPIClient.m
//  universityFace
//
//  Created by 阮 沧晖 on 14-9-26.
//  Copyright (c) 2014年 阮 沧晖. All rights reserved.
//

#import "DDNetWorkAPIClient.h"
#import "DataController.h"
#import "UFAPI.h"
#import "NSString+MD5.h"

#import "DDTopic.h"
#import "DDAddress.h"
#import "DDTJ.h"
#import "DDAnswerStat.h"
#import "DDQuestionAnswerList.h"
#import "DDQuestionAnswerReply.h"
#import "ModelQuestionList.h"
#import "ModelQuestionCourse.h"
#import "AFHTTPRequestOperationManager.h"

#import "JSONKit.h"
#define CLIENT @"app"
#define PLATCODE @"IOS"
#define CLIENT_SECRET @"f50aa247a3e56eb5ee744a983e2ff9d5"

@implementation DDNetWorkAPIClient
- (id)init
{
    if ([super init]) {
        sharedUser = [DDSharedUser shared];
    }
    return self;
}
#pragma mark -COMMON方法
- (void)postURL:(NSString *)urlWithString params:(NSDictionary*)params CompletionBlock:(void (^)(BOOL isSuccess, NSDictionary *result, NSString *status,id object))completionBlock
{
    DataController *data = [DataController shareDataController];
    
    [data sendHttpRequestBlock:urlWithString parameters:params useCache:NO success:^(AFHTTPRequestOperation *operation, id responseObject, BOOL dataIsFromDisk) {
        NSDictionary *JSON = responseObject;
        NSString *code = [JSON objectForKey:@"code"];
        NSString *message = [JSON objectForKey:@"message"];
        BOOL scueess = [[JSON objectForKey:@"success"] boolValue];
        if ([JSON objectForKey:@"success"]) {
            completionBlock(scueess,JSON, code,message);
            return;
        }
        completionBlock(YES,JSON, code,message);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error, BOOL dataIsFromDisk) {
        NSLog(@"error.userInfo:%@",error.userInfo);
        
        if ([error.description rangeOfString:@"401"].location != NSNotFound) {
//          DDNetWorkAPIClient * network =  [[DDNetWorkAPIClient alloc] init];
//          [network userRefreshAuthToken:^(BOOL isSuccess, NSDictionary *dict, NSString *message, NSString *status) {
//              NSLog(@"%@",message);
//          }];
            
            [[NSNotificationCenter defaultCenter] postNotificationName:@"relogin" object:nil];
            
        }
        
        completionBlock(NO, nil, nil,error);
    }];
    NSLog(@"urlWithString:%@",urlWithString);
}



- (void)succ:(id)obj
{
    NSLog(@"%@",obj);
}
- (void)fail:(NSError *)error
{
    NSLog(@"%@",error.userInfo);
}

#pragma mark AUTH:认证接口
/****************
*   第三方登录时:
*   用户名：第三方的openid
*   password：md5(yyMMdd+用户名倒序+26%trUst#9527)
*       其中：yyMMdd从服务端接口【/api/systime】获取
****************/
-(void)userAuthToken:(NSString *)phoneNum password:(NSString*)password CompletionBlock:(void (^)(BOOL isSuccess,NSDictionary*dict, NSString *message, NSString *status))completionBlock
{
    //URL路径
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleAuthTag:kDDAuthToken];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:@"password" forKey:@"grant_type"];
    [params setValue:CLIENT forKey:@"client_id"];
    [params setValue:CLIENT_SECRET forKey:@"client_secret"];
    [params setValue:phoneNum forKey:@"username"];
    [params setValue:password forKey:@"password"];
    //获取请求
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status, id object) {
        sharedUser.access_token = [result objectForKey:@"access_token"];
        sharedUser.expires_in = [result objectForKey:@"expires_in"];
        sharedUser.refresh_token = [result objectForKey:@"refresh_token"];
        sharedUser.scope = [result objectForKey:@"scope"];
        sharedUser.token_type = [result objectForKey:@"token_type"];
        completionBlock(isSuccess,result,object,status);
    }];
}

-(void)userRefreshAuthToken:(void (^)(BOOL isSuccess,NSDictionary*dict, NSString *message, NSString *status))completionBlock
{
    //URL路径
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleAuthTag:kDDAuthToken];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    DDSharedUser *user = [DDSharedUser shared];
    [params setValue:@"refresh_token" forKey:@"grant_type"];
    [params setValue:CLIENT forKey:@"client_id"];
    [params setValue:CLIENT_SECRET forKey:@"client_secret"];
    [params setValue:user.refresh_token forKey:@"refresh_token"];
    
    //获取请求
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status, id object) {
        sharedUser.access_token = [result objectForKey:@"access_token"];
        sharedUser.expires_in = [result objectForKey:@"expires_in"];
        sharedUser.refresh_token = [result objectForKey:@"refresh_token"];
        sharedUser.scope = [result objectForKey:@"scope"];
        sharedUser.token_type = [result objectForKey:@"token_type"];
        completionBlock(isSuccess,result,object,status);
    }];
}

-(void)userLoginOut:(void (^)(BOOL isSuccess,NSDictionary*dict, NSString *message, NSString *status))completionBlock
{
    //URL路径
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleAuthTag:kDDLoginOut];
    //获取请求
    [self postURL:urlWithString params:@{@"access_token":sharedUser.access_token} CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status, id object) {
        
        NSLog(@"%@",result);
        
        completionBlock(isSuccess,result,object,status);
    }];
}

#pragma mark -用户相关
//获取当前用户信息
-(void) getUserInfo:(NSString *)access_token completionBlock:(void (^)(BOOL isSuccess,NSDictionary *dict, NSString *message, NSString *status))completionBlock
{
    //URL路径
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleUserTag:kDDGetUserInfo];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    //[params setValue:access_token forKey:@"access_token"];
    [params setValue:sharedUser.access_token forKey:@"access_token"];
    //获取请求
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status, id object) {
        
        NSDictionary *data = [result objectForKey:@"data"];
        
        NSLog(@"%@",result);
        NSError *error;
        DDUser *user = [[DDUser alloc] initWithDictionary:data error:&error];
        if (error) {
            NSLog(@"%@",error.userInfo);
        }
//        user.uid = [data objectForKey:@"uid"];
//        user.userName = [data objectForKey:@"userName"];
//        user.no = [data objectForKey:@"no"];
//        user.rank = [data objectForKey:@"rank"];
//        user.nickName = [data objectForKey:@"nickName"];
//        user.name = [data objectForKey:@"name"];
//        user.phoneNumber = [data objectForKey:@"phoneNumber"];
//        user.gender = [data objectForKey:@"gender"];
//        user.birthday = [data objectForKey:@"birthday"];
//        user.school = [data objectForKey:@"school"];
//        user.grade = [data objectForKey:@"grade"];
//        user.clzss = [data objectForKey:@"clzss"];
//        user.recent = [data objectForKey:@"recent"];
//        user.avatarUrl = [data objectForKey:@"avatarUrl"];
//        user.avatarTimestamp = [data objectForKey:@"avatarTimestamp"];
        sharedUser.userInfo = user;
        completionBlock(isSuccess,data,object,status);
    }];
}

//查询是否有绑定第三方账号
/*
*   source  填写：QQ、WEIBO、WEIXIN
*/
- (void)isBind:(NSString *)source accessToken:(NSString *)accessToken completionBlock:(void (^)(BOOL isSuccess, NSDictionary *dict, NSString *message, NSString *status))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleUserTag:kDDIsBind];
    NSString *sign = [[NSString stringWithFormat:@"%@%@%@%@", CLIENT, accessToken, source, CLIENT_SECRET] MD5];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:CLIENT forKey:@"client"];
    [params setValue:source forKey:@"source"];
    [params setValue:accessToken forKey:@"accessToken"];
    [params setValue:sign forKey:@"sign"];
    
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status, id object) {
        NSLog(@"%@",result);
        NSDictionary *data = [result objectForKey:@"data"];
        completionBlock(isSuccess, data, object, status);
    }];
}

//绑定第三方账号
- (void)bindAccountd:(NSString *)user_accessToken openId:(NSString *)openId nickName:(NSString *)nickName accessToken:(NSString *)accessToken source:(NSString *)source validity:(NSString *)validity completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleUserTag:kDDBind];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:user_accessToken forKey:@"access_token"];
    [params setValue:openId forKey:@"openId"];
    [params setValue:nickName forKey:@"nickName"];
    [params setValue:accessToken forKey:@"token"]; //接口文档填写名称为accessToken，平台实际使用的是token －jiangxp
    [params setValue:source forKey:@"source"];
    [params setValue:validity forKey:@"validity"];
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status, id object) {
        NSLog(@"%@",result);
        completionBlock(isSuccess, object, status);
    }];
}

//检查是否为注册用户
- (void)isOpen:(NSString *)userName CompletionBlock:(void (^)(BOOL isSuccess,NSDictionary*dict, NSString *message, NSString *status))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleUserTag:kDDIsOpen];
    NSString *sign = [[NSString stringWithFormat:@"%@%@%@",CLIENT,userName,CLIENT_SECRET] MD5];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:CLIENT forKey:@"client"];
    [params setValue:userName forKey:@"userName"];
    [params setValue:sign forKey:@"sign"];
    
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status, id object) {
        NSLog(@"%@",result);
        NSDictionary *data = [result objectForKey:@"data"];
        completionBlock(isSuccess, data, object, status);
    }];
}

//获取手机验证码
- (void)userPhoneCode:(NSString *)phoneNumber completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleUserTag:kDDUserPhoneCode];
    NSString *sign = [[NSString stringWithFormat:@"%@%@%@", CLIENT, phoneNumber, CLIENT_SECRET] MD5];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:CLIENT forKey:@"client"];
    [params setValue:phoneNumber forKey:@"phoneNumber"];
    [params setObject:sign forKeyedSubscript:@"sign"];
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        NSLog(@"%@",result);
        completionBlock(isSuccess, object, status);
    }];
}

//重置用户密码
- (void)resetPassword:(NSString*)phoneNum phoneCode:(NSString *)phoneCode passwordType:(NSString *)passwordType password:(NSString *)password completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleUserTag:kDDResetPassword];
    NSString *sign = [[NSString stringWithFormat:@"%@%@%@%@%@", CLIENT, phoneNum, password, phoneCode, CLIENT_SECRET] MD5];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:CLIENT forKey:@"client"];
    [params setValue:phoneNum forKey:@"phoneNumber"];
    [params setValue:phoneCode forKey:@"code"];
    [params setValue:passwordType forKey:@"type"];
    [params setValue:password forKey:@"password"];
    [params setValue:sign forKey:@"sign"];
    
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        NSLog(@"%@",result);
        completionBlock(isSuccess, object, status);
    }];
    
}

//注册用户
-(void) userRegister:(NSString *)phoneNum phoneCode:(NSString *)phoneCode password:(NSString *)password nickName:(NSString *)nickName fid:(NSString *)fid completionBlock:(void (^)(BOOL isSuccess, NSDictionary *dict, NSString *message, NSString *status, NSDictionary *result))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleUserTag:kDDUserRegister];
    NSString *sign = [[NSString stringWithFormat:@"%@%@%@%@", CLIENT, phoneNum, password, CLIENT_SECRET] MD5];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:CLIENT forKey:@"client"];
    [params setValue:phoneNum forKey:@"userName"];
    [params setValue:phoneCode forKey:@"phoneCode"];
    [params setValue:password forKey:@"password"];
    [params setValue:nickName forKey:@"nickName"];
    [params setValue:PLATCODE forKey:@"platCode"];
    [params setValue:fid forKey:@"fid"];
    [params setValue:sign forKey:@"sign"];
    
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        NSLog(@"%@",result);
        NSDictionary *data = [result objectForKey:@"data"];
        completionBlock(isSuccess, data, object, status, result);
    }];
}

//修改用户信息
- (void)userEdit:(NSString *)userName nickName:(NSString *)nickName name:(NSString *)name gender:(NSString *)gender birthday:(NSString *)birthday phoneNum:(NSString *)phoneNum school:(NSString *)school grade:(NSString *)grade clzss:(NSString *)clzss recent:(NSString *)recent topicId:(NSString *)topicId completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleUserTag:kDDUserEdit];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:sharedUser.access_token forKey:@"access_token"];
    [params setValue:userName forKey:@"userName"];
    [params setValue:nickName forKey:@"nickName"];
    [params setValue:name forKey:@"name"];
    [params setValue:gender forKey:@"gender"];
    if (birthday.length > 0) {
        [params setValue:birthday forKey:@"birthday"];
    }
    [params setValue:phoneNum forKey:@"phoneNumber"];
    [params setValue:school forKey:@"school"];
    [params setValue:grade forKey:@"grade"];
    [params setValue:clzss forKey:@"clzss"];
    [params setValue:topicId forKey:@"topicId"];
    if (recent.length > 0) {
        [params setValue:recent forKey:@"recent"];
    }
    
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        NSLog(@"%@",result);
        completionBlock(isSuccess, object, status);
    }];
}

//修改用户密码
- (void)passwordChange:(NSString *)type oldPassword:(NSString *)oldPassword password:(NSString *)password completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleUserTag:kDDPasswordChange];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:sharedUser.access_token forKey:@"access_token"];
    [params setValue:type forKey:@"type"];
    [params setValue:oldPassword forKey:@"oldPassword"];
    [params setValue:password forKey:@"password"];
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        NSLog(@"%@",result);
        completionBlock(isSuccess, object, status);
    }];
}

//修改用户头像
- (void)avatarSave:(NSString *)data completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleUserTag:kDDAvatarSave];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:sharedUser.access_token forKey:@"access_token"];
    [params setValue:data forKey:@"data"];
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        NSLog(@"%@",result);
        completionBlock(isSuccess, object, status);
    }];
}

//获取用户头像地址
- (void)userAvatar:(NSString *)uid size:(NSString *)size completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status))completionBlock
{
    NSString *urlWithString = [NSString stringWithFormat:@"%@%@", [[UFAPI shared] urlStringWithModuleUserTag:kDDUserAvatar], uid];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:sharedUser.access_token forKey:@"access_token"];
    [params setValue:uid forKey:@"uid"];
    [params setValue:size forKey:@"size"];
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        NSLog(@"%@",result);
        completionBlock(isSuccess, object, status);
    }];

}
//批量获取用户头像地址
- (void)avatarGet:(NSArray *)uids size:(NSString *)size completionBlock:(void (^)(BOOL isSuccess, NSDictionary *dict, NSString *message, NSString *status))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleUserTag:kDDAvatarGet];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:sharedUser.access_token forKey:@"access_token"];
    
    NSString *uidstr = @"";
    int i = 0;
    for (NSString *string in uids) {
        if (i == 0)
        {
          uidstr =  [uidstr stringByAppendingFormat:@"uids=%@",string];
        }
        else
        {
          uidstr =  [uidstr stringByAppendingFormat:@"&&uids=%@",string];
        }
        i++;
    }
    
   // [params setValue:uidstr forKey:@"uids"];
    [params setValue:size forKey:@"size"];
    urlWithString = [NSString stringWithFormat:@"%@?%@",urlWithString,uidstr];
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        NSLog(@"%@",result);
        NSDictionary *data = [result objectForKey:@"data"];
        completionBlock(isSuccess, data, object, status);
    }];
}
//更新用户心情
- (void)recentSave:(NSString *)content completionBlock:(void (^)(BOOL isSuccess, NSDictionary *dict, NSString *message, NSString *status))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleUserTag:kDDRecentSave];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:sharedUser.access_token forKey:@"access_token"];
    [params setValue:content forKey:@"content"];
    
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        NSLog(@"%@",result);
        NSDictionary *data = [result objectForKey:@"data"];
        completionBlock(isSuccess, data, object, status);
    }];
}
//分享纪录
- (void)dailyShare:(void (^)(BOOL isSuccess, NSDictionary *dict, NSString *message, NSString *status))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleUserTag:kDDDailyShare];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:sharedUser.access_token forKey:@"access_token"];
    
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        NSLog(@"%@",result);
        NSDictionary *data = [result objectForKey:@"data"];
        completionBlock(isSuccess, data, object, status);
    }];
}

//每日签到
- (void)dailySign:(void (^)(BOOL isSuccess, NSDictionary *dict, NSString *message, NSString *status))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleUserTag:kDDDailySign];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:sharedUser.access_token forKey:@"access_token"];
    
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        NSLog(@"%@",result);
        NSDictionary *data = [result objectForKey:@"data"];
        completionBlock(isSuccess, data, object, status);
    }];
}

#pragma mark -主业务
-(void) mainTopicList:(NSDictionary *)mainParams completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status,id object))completionBlock
{
    
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleMainTag:kDDTopicList];
    NSLog(@"%@",urlWithString);
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:mainParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];    
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
       // NSLog(@"%@",result);
        NSDictionary *data = [result objectForKey:@"data"];
        NSError *error;
        DDTopic *topic = [[DDTopic alloc] initWithDictionary:data error:&error];
        if (error) {
            NSLog(@"%@",error.userInfo);
        }
        completionBlock(isSuccess,object,status,topic);
    }];
}

-(void)mainDefaultCourseList:(void (^)(BOOL isSuccess, NSString *message, NSString *status,id object))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleMainTag:kDDDefaultCourseList];
    NSLog(@"%@",urlWithString);
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        NSError * myError = nil;
        ModelQuestionCourse * model = [[ModelQuestionCourse alloc]initWithDictionary:result error:&myError];
        completionBlock(isSuccess,object,status,model);
    }];
}

//获取我的科目列表
-(void) mainCoursetList:(NSDictionary *)mainParams completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status,id object))completionBlock
{

    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleMainTag:kDDCoursetList];
    NSLog(@"%@",urlWithString);
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:mainParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {

        NSError * myError = nil;
        ModelQuestionCourse * model = [[ModelQuestionCourse alloc]initWithDictionary:result error:&myError];
        
        completionBlock(isSuccess,object,status,model);
    }];
}

//获取发布详情
-(void)mainTopicDetail:(NSDictionary *)mainParams completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status, id object))completionBlock{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleMainTag:kDDQuestionPublishDetail];
    NSLog(@"%@",urlWithString);
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:mainParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {


        completionBlock(isSuccess,object,status,result);
    }];
}

//修改发布
-(void)mainTopicEdit:(NSDictionary *)mainParams completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status, id object))completionBlock{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleMainTag:kDDQuestionTopicEdit];
    NSLog(@"%@",urlWithString);
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:mainParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        completionBlock(isSuccess,object,status,result);
    }];

}

//增加我的科目
-(void) mainCoursetAdd:(NSDictionary *)mainParams completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status,id object))completionBlock{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleMainTag:kDDAddCourse];
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:mainParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        completionBlock(isSuccess,object,status,result);
    }];
}

//修改科目
-(void)mainCourseEdit:(NSDictionary *)mainParams completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status,id object))completionBlock{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleMainTag:kDDQuestionCourseEdit];
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:mainParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        completionBlock(isSuccess,object,status,result);
    }];
}


//增加用户题目标签
-(void) mainTopicTagAdd:(NSDictionary *)mainParams completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status,id object))completionBlock{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleMainTag:kDDQuestionTopicTagAdd];
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:mainParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
         NSLog(@"%@",result);
        NSNumber * questionIndex = [result objectForKey:@"data"];
        completionBlock(isSuccess,object,status,questionIndex);
    }];
}

//保存题目
-(void) mainQuestionSave:(NSDictionary *)mainParams completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status,id object))completionBlock{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleMainTag:kDDQuestionSave];
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:mainParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        NSNumber * questionIndex = [result objectForKey:@"data"];
        completionBlock(isSuccess,object,status,questionIndex);
    }];
}

//获取我的题库
-(void) mainQuestionList:(NSDictionary *)mainParams completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status,id object))completionBlock{

    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleMainTag:kDDQuestionList];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValuesForKeysWithDictionary:mainParams];

    [params setObject:sharedUser.access_token forKey:@"access_token"];
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        NSDictionary *data = [result objectForKey:@"data"];
        NSError * myError = nil;
        ModelQuestionList * model = [[ModelQuestionList alloc]initWithDictionary:data error:&myError];
        if (myError == nil) {
            completionBlock(isSuccess,object,status,model);
        }else{
            completionBlock(isSuccess,object,status,nil);
        }
    }];
}

//上传发布
-(void) mainTopicSave:(NSDictionary *)mainParams completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status,id object))completionBlock{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleMainTag:kDDTopicSave];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValuesForKeysWithDictionary:mainParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

    NSMutableString * mutiString = [[NSMutableString alloc]initWithString:urlWithString];
    [mutiString appendString:@"?"];
    NSMutableArray * keysArray = [[NSMutableArray alloc]initWithArray:params.allKeys];
    NSMutableArray * resultProcessArray = [[NSMutableArray alloc]init];
    for (int i = 0; i < params.allKeys.count; i++) {
        if ([keysArray[i] isEqualToString:@"questions"]) {
            NSArray * arrayTemp = params[@"questions"];
            for (int j = 0; j < [arrayTemp count]; j++) {
                [resultProcessArray addObject:@{@"questions" : arrayTemp[j]}];
            }
        }else{
            [resultProcessArray addObject:@{keysArray[i] : [params objectForKey:keysArray[i]]}];
        }
    }

    for (int i = 0; i < resultProcessArray.count; i++) {
        NSDictionary * dic = resultProcessArray[i];
        if (i == 0) {
            [mutiString appendFormat:@"%@=%@",[dic.allKeys firstObject],[dic.allValues firstObject]];
        }else{
            [mutiString appendFormat:@"&%@=%@",[dic.allKeys firstObject],[dic.allValues firstObject]];
        }
    }

    NSURL * url = [NSURL URLWithString:mutiString];
    NSMutableURLRequest * request = [[NSMutableURLRequest alloc]initWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30];
    NSOperation * op = [manager HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary * dic = responseObject;
       
        completionBlock([dic[@"success"] boolValue],dic[@"message"],dic[@"code"],dic[@"data"]);

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        completionBlock(NO,@"失败",@"909",nil);
    }];
    [manager.operationQueue addOperation:op];
}


//获取我的发布
-(void) mainMyTopicList:(NSDictionary *)mainParams completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status,id object))completionBlock{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleMainTag:kDDMyTopicList];
    //NSLog(@"%@",urlWithString);
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:mainParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        // NSLog(@"%@",result);
        NSDictionary *data = [result objectForKey:@"data"];
        completionBlock(isSuccess,object,status,data);
    }];
}


-(void) mainAnswerSave:(NSDictionary *)mainParams completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status,id object))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleMainTag:kDDAnswerSave];
    //NSLog(@"%@",urlWithString);
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:mainParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        // NSLog(@"%@",result);
        NSDictionary *data = [result objectForKey:@"data"];
        completionBlock(isSuccess,object,status,data);
    }];

}

-(void)mainMarkSave:(NSDictionary *)mainParams completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status,id object))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleMainTag:kDDMarkSave];
    //NSLog(@"%@",urlWithString);
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:mainParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        // NSLog(@"%@",result);
        NSDictionary *data = [result objectForKey:@"data"];
        completionBlock(isSuccess,object,status,data);
    }];

}


-(void)mainMarkRemove:(NSDictionary *)mainParams completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status,id object))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleMainTag:kDDMarkRemove];
    //NSLog(@"%@",urlWithString);
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:mainParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        // NSLog(@"%@",result);
        NSDictionary *data = [result objectForKey:@"data"];
        completionBlock(isSuccess,object,status,data);
    }];
    
}

- (void)markList:(NSDictionary *)mainParams completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status,id object))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleMainTag:kDDMarkList];
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:mainParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        // NSLog(@"%@",result);
        NSDictionary *data = [result objectForKey:@"data"];
        NSError *error;
        DDTopic *topic = [[DDTopic alloc] initWithDictionary:data error:&error];
        if (error) {
            NSLog(@"%@",error.userInfo);
        }
        completionBlock(isSuccess,object,status,topic);
    }];
}

-(void) mainAnswerList:(NSDictionary *)mainParams completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status,id object))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleMainTag:kDDAnswerList];
    NSLog(@"%@",urlWithString);
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:mainParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        // NSLog(@"%@",result);
        NSDictionary *data = [result objectForKey:@"data"];
        NSError *error;
        DDTopic *topic = [[DDTopic alloc] initWithDictionary:data error:&error];
        if (error) {
            NSLog(@"%@",error.userInfo);
        }
        completionBlock(isSuccess,object,status,topic);
    }];
}


-(void) mainAnswerUser:(NSDictionary *)mainParams completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status,id object))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleMainTag:kDDAnswerUser];
    NSLog(@"%@",urlWithString);
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:mainParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        // NSLog(@"%@",result);
        //NSDictionary *data = [result objectForKey:@"data"];
        NSError *error;
        DDTJ *tj = [[DDTJ alloc] initWithDictionary:result error:&error];
        if (error) {
            NSLog(@"%@",error.userInfo);
        }
        completionBlock(isSuccess,object,status,tj);
    }];

}


-(void) mainAnswerStat:(NSDictionary *)mainParams completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status,id object))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleMainTag:kDDAnswerStat];
    NSLog(@"%@",urlWithString);
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:mainParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        // NSLog(@"%@",result);
        //NSDictionary *data = [result objectForKey:@"data"];
        NSError *error;
        DDAnswerStat *stat = [[DDAnswerStat alloc] initWithDictionary:result error:&error];
        if (error) {
            NSLog(@"%@",error.userInfo);
        }
        completionBlock(isSuccess,object,status,stat);
    }];
}

-(void) mainQuestionAnswerList:(NSDictionary *)mainParams completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status,id object))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleMainTag:kDDQuestionAnswerList];
    NSLog(@"MD=======%@",urlWithString);
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:mainParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
            
        NSError *error;
        DDQuestionAnswerList *answerList = [[DDQuestionAnswerList alloc] initWithDictionary:[result objectForKey:@"data"] error:&error];
        if (error) {
            NSLog(@"%@",error.userInfo);
        }
        completionBlock(isSuccess,object,status,answerList);
    }];
}

-(void) mainQuestionReplyList:(NSDictionary *)mainParams completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status,id object))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleMainTag:kDDQuestionAnswerReplyList];
    NSLog(@"MD==========%@",urlWithString);
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:mainParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {

        NSError *error;
        DDQuestionAnswerReply *replylist = [[DDQuestionAnswerReply alloc] initWithDictionary:[result objectForKey:@"data"] error:&error];
        if (error) {
            NSLog(@"%@",error.userInfo);
        }
        completionBlock(isSuccess,object,status,replylist);
    }];
}

//追问
-(void) mainQuestionReply:(NSDictionary *)mainParams completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status,id object))completionBlock{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleMainTag:kDDQuestionAnswerReply];
    NSLog(@"%@",urlWithString);
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:mainParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        completionBlock(isSuccess,object,status,result);
    }];
}

//对作答进行评分
-(void) mainQuestionAnswerEvaluate:(NSDictionary *)mainParams completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status,id object))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleMainTag:kDDQuestionAnswerEvaluate];
    NSLog(@"%@",urlWithString);
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:mainParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];

    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        completionBlock(isSuccess,object,status,result);
    }];
}

//采纳答案
-(void) mainQuestionAnswerAdopt:(NSDictionary *)mainParams completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status,id object))completionBlock{

    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleMainTag:kDDQuestionAnswerAdopt];
    NSLog(@"%@",urlWithString);
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:mainParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];

    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        completionBlock(isSuccess,object,status,result);
    }];
}

-(void) mainANswerSubmit:(NSDictionary *)mainParams completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status,id object))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleMainTag:kDDAnswerSubmit];
    NSLog(@"%@",urlWithString);
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:mainParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        
//        NSError *error;
//        DDQuestionAnswerReply *replylist = [[DDQuestionAnswerReply alloc] initWithDictionary:[result objectForKey:@"data"] error:&error];
//        if (error) {
//            NSLog(@"%@",error.userInfo);
//        }
        completionBlock(isSuccess,object,status,result);
    }];
}


#pragma mark -通用接口
//获取系统时间
- (void)getSystime:(void (^)(BOOL isSuccess, NSString *message, NSString *status,id object))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithGeneralTag:KUFGetSystime];
    [self postURL:urlWithString params:nil CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        NSLog(@"%@",result);
        NSDictionary *data = [result objectForKey:@"data"];
        completionBlock(isSuccess, object, status, data);
    }];
}
- (void)uploadFile:(NSDictionary *)commonParams completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status,id object))completionBlock
{
    
    NSString *urlWithString = [[UFAPI shared] urlStringWithGeneralTag:kDDUpload];
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:commonParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    //获取请求
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status, id object) {
        completionBlock(isSuccess,object,status,result);
    }];

}
- (void)uploadImage:(NSDictionary *)commonParams completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status,id object))completionBlock
{
    
    NSString *urlWithString = [[UFAPI shared] urlStringWithGeneralTag:kDDUploadIMG];
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:commonParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    //获取请求
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status, id object) {
        completionBlock(isSuccess,object,status,result);
    }];
    
}

- (void)feekback:(NSDictionary *)commonParams completionBlock:(void (^)(BOOL isSuccess, NSDictionary *dict, NSString *message, NSString *status))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithGeneralTag:kCommonFeekback];
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:commonParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        NSLog(@"%@",result);
        NSDictionary *data = [result objectForKey:@"data"];
        completionBlock(isSuccess, data, object, status);
    }];
}

- (void)adList:(NSDictionary *)commonParams completionBlock:(void (^)(BOOL isSuccess, NSString *message, NSString *status,id object))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithGeneralTag:kDDAdList];
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:commonParams];
    //获取请求
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status, id object) {
        completionBlock(isSuccess,object,status,result);
    }];
}
- (void)getAbout:(void (^)(BOOL isSuccess, NSString *message, NSString *status,id object))completionBlock
{
    //    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    //    CFShow((__bridge CFTypeRef)(infoDictionary));
    //    NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
    
    NSString *urlWithString = [[UFAPI shared] urlStringWithGeneralTag:kCommonAbout];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setObject:PLATCODE forKey:@"platCode"];
    [params setObject:@"1" forKey:@"versionCode"];  //需要整形，先写死
    
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        NSLog(@"%@",result);
        NSDictionary *data = [result objectForKey:@"data"];
        completionBlock(isSuccess, object, status, data);
    }];
}


- (void)getCheckVersion:(void (^)(BOOL isSuccess, NSDictionary *dict, NSString *message, NSString *status))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithGeneralTag:kCommonCheckVersion];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setObject:PLATCODE forKey:@"platCode"];
    [params setObject:@"1" forKey:@"versionCode"];  //需要整形，先写死
    
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        NSLog(@"%@",result);
        NSDictionary *data = [result objectForKey:@"data"];
        completionBlock(isSuccess, data, object, status);
    }];
}




#pragma mark - 积分接口
- (void)queryIntegral:(void (^)(BOOL isSuccess, NSDictionary *dict, NSString *message, NSString *status))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleIntegralTag:kIntegralQuery];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        NSLog(@"%@",result);
        NSDictionary *data = [result objectForKey:@"data"];
        completionBlock(isSuccess, data, object, status);
    }];
}

- (void)gitGave:(NSDictionary *)integralParams completionBlock:(void (^)(BOOL isSuccess, NSDictionary *dict, NSString *message, NSString *status))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleIntegralTag:kDDGifGave];
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:integralParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        NSLog(@"%@",result);
        NSDictionary *data = [result objectForKey:@"data"];
        completionBlock(isSuccess, data, object, status);
    }];
}

- (void)giftQuery:(NSDictionary *)integralParams completionBlock:(void (^)(BOOL isSuccess, NSDictionary *dict, NSString *message, NSString *status))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithModuleIntegralTag:kDDGiftQuery];
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:integralParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        NSLog(@"%@",result);
        NSDictionary *data = [result objectForKey:@"data"];
        completionBlock(isSuccess, data, object, status);
    }];
}

#pragma mark - 礼品接口
- (void)queryGitf:(void (^)(BOOL isSuccess, NSDictionary *dict, NSString *message, NSString *status))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithGiftTag:kGiftQuery];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setObject:@"true" forKey:@"marketable"];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        NSLog(@"%@",result);
        NSDictionary *data = [result objectForKey:@"data"];
        completionBlock(isSuccess, data, object, status);
    }];
}

//查询礼品兑换订单信息
- (void)queryGitfOrder:(void (^)(BOOL isSuccess, NSDictionary *dict, NSString *message, NSString *status))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithGiftTag:kGiftOrderQuery];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        NSLog(@"%@",result);
        NSDictionary *data = [result objectForKey:@"data"];
        completionBlock(isSuccess, data, object, status);
    }];
}

//兑换礼品
- (void)gitExchange:(NSDictionary *)integralParams completionBlock:(void (^)(BOOL isSuccess, NSDictionary *dict, NSString *message, NSString *status))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithGiftTag:kGiftExchange];
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:integralParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        NSLog(@"%@",result);
        NSDictionary *data = [result objectForKey:@"data"];
        completionBlock(isSuccess, data, object, status);
    }];
}

//收货地址
- (void)queryAddress:(void (^)(BOOL isSuccess, id address, NSString *message, NSString *status))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithAddressTag:kAddressQuery];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        NSLog(@"%@",result);
        DDAddress *address = [[DDAddress alloc] initWithDictionary:result error:nil];
        completionBlock(isSuccess, address, object, status);
    }];
}

- (void)addAddress:(NSDictionary *)addressParams completionBlock:(void (^)(BOOL isSuccess, NSDictionary *dict, NSString *message, NSString *status))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithAddressTag:kAddressAdd];
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:addressParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        NSLog(@"%@",result);
        NSDictionary *data = [result objectForKey:@"data"];
        completionBlock(isSuccess, data, object, status);
    }];
}
- (void)updateAddress:(NSDictionary *)addressParams completionBlock:(void (^)(BOOL isSuccess, NSDictionary *dict, NSString *message, NSString *status))completionBlock
{
    NSString *urlWithString = [[UFAPI shared] urlStringWithAddressTag:kAddressUpdate];
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:addressParams];
    [params setObject:sharedUser.access_token forKey:@"access_token"];
    
    [self postURL:urlWithString params:params CompletionBlock:^(BOOL isSuccess, NSDictionary *result, NSString *status,id object) {
        NSLog(@"%@",result);
        NSDictionary *data = [result objectForKey:@"data"];
        completionBlock(isSuccess, data, object, status);
    }];
}

@end
